package com.jwthhealth_pub.old.sportfitness.view.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.common.Constant;
import com.jwthhealth_pub.old.common.ImageLoader;
import com.jwthhealth_pub.old.sportfitness.module.SprotCourseInfoModule;
import com.jwthhealth_pub.old.sportfitness.view.SportCourseInfoActivity;
import com.jwthhealth_pub.old.sportfitness.view.SportCourseListActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/1/5.
 */
public class SprotCourseInfoAdapter extends RecyclerView.Adapter {

    public SportCourseInfoActivity activity;
    List<SprotCourseInfoModule.DataBean.VideoListBean> list;
    SprotCourseInfoModule.DataBean data;

    public SprotCourseInfoAdapter(SportCourseInfoActivity sportCourseInfoActivity, SprotCourseInfoModule.DataBean data) {
        this.activity = sportCourseInfoActivity;
        this.data = data;
        list = data.getVideo_list();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new HeadViewHolder(LayoutInflater.from(activity).inflate(R.layout.item_sport_course_info_video_list, parent, false));
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
        HeadViewHolder headViewHolder = (HeadViewHolder) holder;
        final SprotCourseInfoModule.DataBean.VideoListBean videoListBean = list.get(position);
//        Picasso.with(activity).load(videoListBean.getThumb()).into(headViewHolder.img);
        ImageLoader.picasso(videoListBean.getThumb(), headViewHolder.img);
        headViewHolder.title.setText(videoListBean.getName());
        headViewHolder.count.setText(videoListBean.getDegree() + "次");
        headViewHolder.rest_time.setText(videoListBean.getRest_time() + "s");

        headViewHolder.clickLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putSerializable(Constant.SPORT_DATA, data);
                bundle.putInt(Constant.SPORT_INDEX, position);
                // TODO: 2017/1/5 jump
                Intent intent = new Intent(activity, SportCourseListActivity.class);
                intent.putExtras(bundle);
                activity.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    private class HeadViewHolder extends RecyclerView.ViewHolder{

        RelativeLayout clickLayout;
        ImageView img;
        TextView title, count, rest_time;

        public HeadViewHolder(View itemView) {
            super(itemView);
            clickLayout = (RelativeLayout) itemView.findViewById(R.id.img_layout);
            img = (ImageView) itemView.findViewById(R.id.img);
            title = (TextView) itemView.findViewById(R.id.head_title);
            count = (TextView) itemView.findViewById(R.id.count);
            rest_time = (TextView) itemView.findViewById(R.id.rest_time);
        }
    }
}
